class Admin::PrintProductController < Admin::BaseController
  
  active_scaffold :print_product do |config|
      config.label = "印刷产品"
      config.create.columns = [:category, :name, :model, :description]
      config.columns = [:category, :name, :model, :description]
      config.list.columns.exclude :description
      list.sorting = {:name => 'ASC'}
      columns[:category].label = "分类"
      columns[:name].label = "名称"
      columns[:description].label = "描述"
      columns[:model].label = "模型名称"
  end
  
  auto_complete_for :print_category, :name, :limit => 20, :order => 'name ASC'
  
  protected
  def before_create_save(record)
    set_category(record)
  end
  
  def before_update_save(record)
    set_category(record)
  end
  
  private
  def set_category(record)
    parnet_category_name = params[:print_category][:name]
    parentCategory = PrintCategory.find_by_name(parnet_category_name)
    record.print_category_id = parentCategory.id
  end
end
